home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Micro R&D 5: Mand 2000
/
Mand 2000 - Micro R&D CD-ROM Vol 5.iso
/
bonusstuff
/
simplemand.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-12
|
1KB
|
69 lines
/*
This is a very tiny program to demonstrate just how simple it is to
generate a Mandelbrot set. This 68 line program calculates the outer
Mandelbrot set and displays it in ASCII characters on a console. This
program does not allow you to zoom. Copyright © 1993 CygnusSoftware.
*/
#include "stdio.h"
#define MaxIters 60
#define XSIZE 70
#define YSIZE 22
#define BLACK -1
#define LEFT -2.0
#define RIGHT 1.0
#define TOP 1.0
#define BOTTOM -1.0
main(int argc, char *argv[])
{
short x, y, counter;
long double zr, zi, cr, ci, rsquared, isquared;
for (y = 0; y < YSIZE; y++)
{
for (x = 0; x < XSIZE; x++)
{
zr = 0.0;
zi = 0.0;
cr = LEFT + x * (RIGHT - LEFT) / XSIZE;
ci = TOP + y * (BOTTOM - TOP) / YSIZE;
rsquared = zr * zr;
isquared = zi * zi;
/* The next eleven lines actually do all of the work. */
for (counter = 0; rsquared + isquared <= 4.0 &&
counter < MaxIters; counter++)
{
zi = zr * zi * 2;
zi += ci;
zr = rsquared - isquared;
zr += cr;
rsquared = zr * zr;
isquared = zi * zi;
}
if (rsquared + isquared <= 4.0)
putchar('*'); /* In the set. */
else
putchar(' '); /* Not in the set. */
}
putchar('\n');
}
puts("SimpleMand: Copyright © 1993 Cygnus Software.\nThat's it.");
return 0;
}